home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3596 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  56 lines

  1. Path: oxy.rust.net!usenet
  2. From: ebennett@rust.net
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Visual C++ 4.0 lacking initializers?
  5. Date: Thu, 25 Jan 1996 04:01:19 GMT
  6. Organization: Rust Net - High Speed Internet in Detroit  810-642-2276
  7. Message-ID: <4e6koa$ela@oxy.rust.net>
  8. References: <31049C46.A26@oz.is>
  9. NNTP-Posting-Host: liv-18.rust.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Hßlfdan Ingvarsson <halfdan@oz.is> wrote:
  13.  
  14. >Is it me or is this sort of code not possible with VC++ 4.0? 
  15.  
  16. >// Declarations of class Foo
  17.  
  18. >// VC++ Complains about the line below with the error
  19. >// error C2436: '__ctor' : cannot initialize member functions
  20. >Foo::Foo(void) : Foo::Foo(10) {}
  21.  
  22. >Foo::Foo(x)
  23. >{
  24. >  // Some stuff
  25. >}
  26.  
  27. I'm not 100% positive, but I do not believe this is possible with any
  28. C++ compiler.   I do not think that a class constructor can call
  29. another constructor of the same class.
  30.  
  31. I'm also not sure if a constructor with a void parameter is legal.
  32.  
  33. The solution is to create an init method like so:
  34.  
  35.   Foo::Init (x)
  36.   {
  37.      // do some stuff
  38.   };
  39.  
  40.   Foo::Foo()
  41.   {
  42.       Init(10);
  43.   };
  44.  
  45.   Foo::Foo(x)
  46.   {
  47.      Init(x);
  48.   };
  49.  
  50. Don't forget type specifiers for the x's in the parameter
  51. declarations, by the way.
  52.  
  53. Earl Bennett
  54.  
  55.  
  56.